﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WURFL;
using WURFL.Config;


namespace Nucleo.Wurfl.Creator
{
	public class HttpContextWurflCreator : BaseWurflCreator
	{
		public const String WurflDataFilePath = "~/App_Data/wurfl-latest.zip";
		public const String WurflPatchFilePath = "~/App_Data/web_browsers_patch.xml";


		protected override string DataFile
		{
			get { return WurflDataFilePath; }
		}

		protected override string PatchFile
		{
			get { return WurflPatchFilePath; }
		}


		public override WURFL.IWURFLManager CreateManager()
		{
			var wurflDataFile = HttpContext.Current.Server.MapPath(WurflDataFilePath);
			var wurflPatchFile = HttpContext.Current.Server.MapPath(WurflPatchFilePath);

			var configurer = new InMemoryConfigurer()
					.MainFile(wurflDataFile)
					.PatchFile(wurflPatchFile);
			var manager = WURFLManagerBuilder.Build(configurer);

			return manager;
		}
	}
}
